package com.ruoyi.project.common;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.framework.config.RuoYiConfig;
import com.ruoyi.framework.config.ServerConfig;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.common.component.AliOSSComponent;
import com.ruoyi.project.common.domain.vo.DictDataVo;
import com.ruoyi.project.system.domain.SysDictData;
import com.ruoyi.project.system.service.ISysDictDataService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 通用请求处理
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("common/dict")
public class CommonDictController
{
    private static final Logger log = LoggerFactory.getLogger(CommonDictController.class);

    @Autowired
    private ISysDictDataService dictDataService;

    /**
     * 根据字典类型查询字典数据信息
     */
    @PostMapping(value = "/dictType/{dictType}")
    public AjaxResult dictType(@PathVariable String dictType)
    {
        List<SysDictData> sysDictData = dictDataService.selectDictDataByType(dictType);
        DictDataVo dataVo = new DictDataVo();
        if (CollUtil.isNotEmpty(sysDictData)){
            List<String> valueOps = Lists.newArrayList();
            List<String> labelOps = Lists.newArrayList();
            for (SysDictData data:sysDictData){
                valueOps.add(data.getDictValue());
                labelOps.add(data.getDictLabel());
            }
            dataVo.setValueOps(valueOps);
            dataVo.setLabelOps(labelOps);
        }
        return AjaxResult.success(dataVo);
    }
}
